<?php

class TshirtController extends BaseController {

//tshirt Type
	public function getTshirt()
	{
		Session::forget('filter');
		$tshirttype = DB::table('ref_tshirt')
				->where('tshirt_isdelete','=',0)
				->paginate(10);
		return View::make('admin.tshirt.tshirt')->with('tshirttype',$tshirttype);
	}

	public function postTshirt()
	{
		$filter = Input::get('filter');
		Session::put('filter',Input::get('filter'));
		$tshirttype = DB::table('ref_tshirt')
		->where('tshirt_isdelete','=',0)
		->where('tshirt_type_of_material','LIKE','%'.$filter.'%')
		->paginate(10);
		return View::make('admin.tshirt.tshirt')->with('tshirttype',$tshirttype);
	}

	public function postAddtshirt()
	{
		$addtshirt = reftshirt::create(Input::all());

		$log = New adminlog();
		$log->admin_log_admin_id = Session::get('admin_id');	
		$log->admin_log_activity = "Add data tshirt";	
		$log->admin_log_date = date('Y-m-d H:i:s');	
		$log->save();
		return Redirect::to('/tshirt')->with('message','Data jenis tshirt berhasil ditambahkan');
	}

	public function postEdittshirt($id)
	{
		$edittshirt = reftshirt::find($id);
		$edittshirt->tshirt_type_of_material = Input::get('tshirt_type_of_material');
		
		$edittshirt->save();

		$log = New adminlog();
		$log->admin_log_admin_id = Session::get('admin_id');	
		$log->admin_log_activity = "Edit data tshirt ".$id;	
		$log->admin_log_date = date('Y-m-d H:i:s');	
		$log->save();
		return Redirect::to('/tshirt')->with('message','Data jenis tshirt berhasil diubah');
	}

	public function postDeletetshirt()
	{
		$tshirts = DB::table('ref_tshirt')
				->get();
		foreach($tshirts as $tshirts){
		if(Input::get($tshirts->tshirt_id)=='1'){
			$tshirt = DB::table('ref_tshirt')
					->where('tshirt_id','=',$tshirts->tshirt_id)
					->update(array('tshirt_isdelete' => 1));

		$log = New adminlog();
		$log->admin_log_admin_id = Session::get('admin_id');	
		$log->admin_log_activity = "Delete data tshirt ".$tshirts->tshirt_id;	
		$log->admin_log_date = date('Y-m-d H:i:s');	
		$log->save();
		}
		}
		return Redirect::to('/tshirt')->with('message','Data jenis tshirt berhasil dihapus');

	}







	//detail
	public function getTshirtdetail($id)
	{	
		Session::forget('filter');
		Session::put('idtshirt',$id);
		$tshirt = DB::table('ref_tshirt')
				->where('tshirt_id','=',$id)
				->first();
		$tshirttype = DB::table('ref_tshirt_detail')
				->where('tshirt_detail_tshirt_id','=',$id)
				->where('tshirt_detail_isdelete','=',0)
				->paginate(10);
		return View::make('admin.tshirt.tshirtdetail',compact('tshirt',$tshirt,'tshirttype',$tshirttype));
	}

		public function postTshirtdetail()
	{
		$tshirtid = Session::get('idtshirt');
		$filter = Input::get('filter');
		Session::put('filter',Input::get('filter'));
		$tshirt = DB::table('ref_tshirt')
				->where('tshirt_id','=',$tshirtid)
				->first();
		$tshirttype = DB::table('ref_tshirt_detail')
		->where('tshirt_detail_tshirt_id','=',$tshirtid)
		->where('tshirt_detail_isdelete','=',0)
		->where('tshirt_detail_price','LIKE','%'.$filter.'%')
		->paginate(10);
		return View::make('admin.tshirt.tshirtdetail',compact('tshirt',$tshirt,'tshirttype',$tshirttype));
	}



	public function postAddtshirtdetail($id)
	{
		$addtshirt = reftshirtdetail::create(Input::all());
		$addtshirt->tshirt_detail_tshirt_id = $id;
		$addtshirt->save();

		$log = New adminlog();
		$log->admin_log_admin_id = Session::get('admin_id');	
		$log->admin_log_activity = "Add data tshirt detail";	
		$log->admin_log_date = date('Y-m-d H:i:s');	
		$log->save();
		return Redirect::to('/tshirt/detail/'.Session::get('idtshirt'))->with('message','Data harga berhasil ditambahkan');
	}

	public function postEdittshirtdetail($id)
	{
		$edittshirt = reftshirtdetail::find($id);
		$edittshirt->tshirt_detail_price = Input::get('tshirt_detail_price');
		$edittshirt->tshirt_detail_qty_price = Input::get('tshirt_detail_qty_price');
		$edittshirt->tshirt_detail_qty_unit = Input::get('tshirt_detail_qty_unit');
		
		$edittshirt->save();

		$log = New adminlog();
		$log->admin_log_admin_id = Session::get('admin_id');	
		$log->admin_log_activity = "Edit data tshirt detail ".$id;	
		$log->admin_log_date = date('Y-m-d H:i:s');	
		$log->save();
		return Redirect::to('/tshirt/detail/'.Session::get('idtshirt'))->with('message','Data harga berhasil diubah');
	}

	public function postDeletetshirtdetail()
	{
		$tshirts = DB::table('ref_tshirt_detail')
				->get();
		foreach($tshirts as $tshirts){
		if(Input::get($tshirts->tshirt_detail_id)=='1'){
			$tshirt = DB::table('ref_tshirt_detail')
					->where('tshirt_detail_id','=',$tshirts->tshirt_detail_id)
					->update(array('tshirt_detail_isdelete' => 1));

		$log = New adminlog();
		$log->admin_log_admin_id = Session::get('admin_id');	
		$log->admin_log_activity = "Delete data tshirt detail ".$tshirts->tshirt_detail_id;	
		$log->admin_log_date = date('Y-m-d H:i:s');	
		$log->save();
		}

		}
		return Redirect::to('/tshirt/detail/'.Session::get('idtshirt'))->with('message','Data harga berhasil dihapus');
		

	}

}